from editor . gui import editor_gui

class frame_fake :
    def __init__ ( self , master ) :
        self . _master = master
        self . _packed = False
        self . _destroyed = False
        
class label_fake :
    def __init__ ( self , master , text ) :
        self . _master = master
        self . _text = text
        self . _packed = False

class button_fake :
    def __init__ ( self , master , text , command ) :
        self . _master = master
        self . _text = text
        self . _command = command
        self . _packed = False

class text_fake :
    pass

class mediator_fake :
    def __init__ ( self ) :
        self . _editor_gui = None
        self . _application_window = None
        self . _widgets = [ ]
        self . _buttons = [ ]
        self . _labels = [ ]
        self . _frames = [ ]
        self . _editor_title = None
        self . _editor_menu_button = None
    def application_window_request ( self ) :
        self . _editor_gui . application_window_reply ( self . _application_window )
    def gui_create_frame_request ( self , master ) :
        frame = frame_fake ( master )
        self . _widgets += [ frame ]
        self . _frames += [ frame ]
        self . _editor_gui . gui_create_frame_reply ( frame )
    def gui_destroy_frame ( self , frame ) :
        frame . _destroyed = True
    def gui_pack ( self , widget , padx = None , pady = None , side = None , fill = None ) :
        widget . _packed = True
    def gui_side_top ( self ) :
        pass
    def gui_side_bottom ( self ) :
        pass
    def gui_create_label_request ( self , master , text ) :
        label = label_fake ( master , text )
        self . _widgets += [ label ]
        self . _labels += [ label ]
        self . _editor_gui . gui_create_label_reply ( label )
    def gui_create_button_request ( self , master , text , command ) :
        button = button_fake ( master , text , command )
        self . _widgets += [ button ]
        self . _buttons += [ button ]
        self . _editor_gui . gui_create_button_reply ( button )
    def gui_create_text_request ( self , master ) :
        self . _editor_gui . gui_create_text_reply ( text_fake ( ) )
    def gui_add_string_to_text_widget ( self , widget , s ) :
        pass
    def gui_disable_text_edit ( self , widget ) :
        pass
    def activate_editor_state_creating_new_query ( self ) :
        pass
    def on_editor_menu_button ( self ) :
        pass
    def localization_editor_title ( self ) :
        return self . _editor_title
    def localization_editor_menu_button ( self ) :
        return self . _editor_menu_button

class editor_gui_tests :
    'editor_gui'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _editor_gui = editor_gui ( self . _mediator )
        self . _mediator . _editor_gui = self . _editor_gui
    def test_show_editor_create_frame ( self ) :
        self . _mediator . _application_window = 'my window'
        self . _editor_gui . show_editor ( )
        frame = self . _mediator . _frames [ 0 ]
        self . _test . assume_equal ( frame . _master , 'my window' )
        self . _test . assume_true ( frame . _packed )
    def test_show_editor_add_menu_button ( self ) :
        self . _mediator . _editor_menu_button = 'my button'
        self . _editor_gui . show_editor ( )
        frame = self . _mediator . _frames [ 0 ]
        button_guts = [ [ button . _master 
                        , button . _text
                        , button . _command
                        , button . _packed 
                      ] for button in self . _mediator . _buttons ]
        self . _test . assume_equal ( button_guts , [ 
            [ frame 
            , 'my button'
            , self . _mediator . on_editor_menu_button 
            , True 
            ] ] )
    def test_hide_editor_destroy_frame ( self ) :
        self . _editor_gui . show_editor ( )
        self . _editor_gui . hide_editor ( )
        frame = self . _mediator . _frames [ 0 ]
        self . _test . assume_true ( frame . _destroyed )
    def test_add_title_label_to_editor ( self ) :
        self . _mediator . _editor_title = 'my title'
        self . _editor_gui . show_editor ( )
        self . _editor_gui . add_title_label_to_editor ( 'my base' )
        frame = self . _mediator . _frames [ 0 ]
        title_masters = [ label . _master for label in self . _mediator . _labels ]
        title_texts = [ label . _text for label in self . _mediator . _labels ]
        title_packed = [ label . _packed for label in self . _mediator . _labels ]
        self . _test . assume_equal ( title_masters [ - 1 : ] , [ frame ] )
        self . _test . assume_equal ( title_texts [ - 1 : ] , [ 'my title my base' ] )
        self . _test . assume_equal ( title_packed [ - 1 : ] , [ True ] )
